const express = require("express");
var app = express();
const multer = require("multer");
//文章文件上传的临时目录 非图片
const upload = multer({ dest: "public/files" });
const router = express.Router();

const userAuthAPI = require("@/api/v1/user_auth");
const menuAPI = require("@/api/v1/menu");
const blogInfoApi = require("@/api/v1/blog_info");
const categoryApi = require("@/api/v1/category");
const tagAPI = require("@/api/v1/tag");
const articleAPI = require("@/api/v1/article");
const uploadAPI = require("@/api/v1/upload");
const commentAPI = require("@/api/v1/comment");
const messageAPI = require("@/api/v1/message");
const pageAPI = require("@/api/v1/page");
const linkAPI = require("@/api/v1/friend_link");
const operationLogAPI = require("@/api/v1/operation_log");
const resourceAPI = require("@/api/v1/resource");
const roleAPI = require("@/api/v1/role");

// 登录接口
router.post("/login", userAuthAPI.login);
router.get("/home", blogInfoApi.GetHomeInfo);

//退出接口
router.get("/logout", userAuthAPI.Logout);

// 用户模块
router.get("/user/info", userAuthAPI.GetInfo);
router.get("/user/online", userAuthAPI.GetOnlineList); //获取用户在线列表
router.get("/user/list", userAuthAPI.GetList);
router.put("/user/current", userAuthAPI.UpdateCurrent);
router.put("/user/current/password", userAuthAPI.UpdateCurrentPassword);

//菜单模块
router.get("/menu/user/list", menuAPI.GetUserMenu);
router.get("/menu/list", menuAPI.GetTreeList); // 菜单列表
router.get("/menu/option", menuAPI.GetOption); // 菜单选项列表(树形)
router.post("/menu", menuAPI.SaveOrUpdate); //新增或更新菜单
router.delete("/menu/:id", menuAPI.Delete);

//博客模块
router.get("/setting/blog-config", blogInfoApi.GetBlogConfig);
router.put("/setting/blog-config", blogInfoApi.UpdateBlogConfig);
router.get("/setting/about", blogInfoApi.GetAbout); //关于我界面数据
router.put("/setting/about", blogInfoApi.UpdateAbout);

//分类相关
router.get("/category/option", categoryApi.GetOption);
router.get("/category/list", categoryApi.GetList);
router.post("/category", categoryApi.SaveOrUpdate); //新增或修改
router.delete("/category", categoryApi.Delete);

//标签模块
router.get("/tag/option", tagAPI.GetOption);
router.get("/tag/list", tagAPI.GetList);
router.post("/tag", tagAPI.SaveOrUpdate); //新增/编辑标签
router.delete("/tag", tagAPI.Delete);

//文章模块
router.get("/article/list", articleAPI.GetList);
router.put("/article/top", articleAPI.UpdateTop); //更新置顶
router.get("/article/:id", articleAPI.GetInfo); //文章详情
router.post("/article", articleAPI.SaveOrUpdate); //更新或新建文章
router.put("/article/soft-delete", articleAPI.SoftDelete); //软删除，只是设置标志位
router.delete("/article", articleAPI.Delete); //物理删除，从数据库中删除
router.post("/article/import", upload.single("file"), articleAPI.Import); //导入文章文件

//评论模块
router.get("/comment/list", commentAPI.GetList);
router.put("/comment/review", commentAPI.UpdateReview); //修改审核
router.delete("/comment", commentAPI.Delete);

//留言模版
router.get("/message/list", messageAPI.GetList);
router.put("/message/review", messageAPI.UpdateReview);
router.delete("/message", messageAPI.Delete);

//页面相关接口
router.get("/page/list", pageAPI.GetList);
router.post("/page", pageAPI.SaveOrUpdate);
router.delete("/page", pageAPI.Delete);

//友链模块
router.get("/link/list", linkAPI.GetList);
router.post("/link", linkAPI.SaveOrUpdate);
router.delete("/link", linkAPI.Delete);

//日志相关
router.get("/operation/log/list", operationLogAPI.GetList);
router.delete("/operation/log", operationLogAPI.Delete);

//文件上传
router.post("/upload", uploadAPI.UploadFile);

// 资源相关
router.get("/resource/list", resourceAPI.GetTreeList);
router.get("/resource/option", resourceAPI.GetOption); //树形资源列表
router.put("/resource/anonymous", resourceAPI.UpdateAnonymous); // 修改资源匿名访问
router.post("/resource", resourceAPI.SaveOrUpdate); // 新增/编辑资源
router.delete("/resource/:id", resourceAPI.Delete);

//角色相关
router.get("/role/list", roleAPI.GetTreeList);
router.post("/role", roleAPI.SaveOrUpdate); // 新增/编辑菜单
router.delete("/role", roleAPI.Delete);

module.exports = router;
